﻿@model HANS_BackStage.Model.DbModel.Backstage_role
@{
    ViewBag.Title = "修改角色";
    var admin_List = ViewBag.Role_Admin as List<HANS_BackStage.Model.DbModel.Backstage_admin>;
}
@section Scripts{
    <script type="text/javascript">
        $(function () {
            function getPermissionTree() {
                var tree=@Html.Raw(ViewBag.PermissionJsonTree);
                return tree;
            }

            //$('#permissionTree').treeview({
            //    data: getPermissionTree()
            //});

            $('#permissionTree').treeview({
                data: getPermissionTree(),
                showCheckbox: true,
                highlightSelected: false,
                //递归选择父节点
                onNodeChecked: function (event, data) {
                    var that = this;
                    function checkParentNode(note){
                        if (note.parentId !==undefined) {
                            var parentNote = $(that).treeview('getNode', note.parentId);
                            $(that).treeview('checkNode', parentNote.nodeId);
                            checkParentNode(parentNote);
                        }
                    }
                    checkParentNode(data);
                },
                //递归取消子节点选择
                onNodeUnchecked: function (event, data) {
                    var that = this;
                    function uncheckChindrenNode(nodes) {
                        if (nodes && nodes.length) {
                            $.each(nodes, function (i, v) {
                                $(that).treeview('uncheckNode', v.nodeId);
                                uncheckChindrenNode(v.nodes);
                            });
                        }
                    }
                    uncheckChindrenNode(data.nodes);
                }
            });

            window.beforeAjaxFormSubmit = function(){
                debugger
                var selectPermissionIds = [];
                var selectNode = $('#permissionTree').treeview('getChecked');
                for(var i = 0; i< selectNode.length; i++){
                    selectPermissionIds.push(selectNode[i].serverId);
                }
                $("#PermissionId").val(selectPermissionIds.join(","));
            }
        });
    </script>
}

<div class="x_panel">
    <!--beginHead-->
    <div class="x_title">
        <h2>相关管理员 <small>HANS</small></h2>
        <ul class="nav navbar-right panel_toolbox">
            <li>
                <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
            </li>
        </ul>
        <div class="clearfix"></div>
    </div>
    <!--endHead-->
    <div class="x_content">
        <div class="form-group">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <table class="table table-striped table-bordered table-hover">
                    <caption><h4>管理员列表</h4></caption>
                    <thead>
                        <tr>
                            <th>账号</th>
                            <th>昵称</th>
                            <th>姓名</th>
                            <th>操作</th>

                        </tr>
                    </thead>
                    <tbody>
                        @{
                            if (admin_List.Count > 0)
                            {
                                foreach (var item in admin_List)
                                {
                                    <tr>
                                        <td>@Html.DisplayFor(i => item.Name)</td>
                                        <td>@Html.DisplayFor(i => item.Nickname)</td>
                                        <td>@Html.DisplayFor(i => item.Truename)</td>
                                        <td>
                                            <a href="@Url.Action("UpdateAdmin","Account",new { Name=item.Name })" class="btn btn-info btn-xs"><i class="fa fa-edit"></i>编辑</a>
                                            <a data-confirmed-text="确认移除该角色？"
                                               data-confirmed-button="确定"
                                               data-confirmed-cancel-button="取消"
                                               data-confirmed-button-class="btn-success"
                                               data-confirmed-url="@Url.Action("DeleteAdminRole", "Account", new { adminId = item.Id,roleId=Model.Id })"
                                               class="btn btn-danger btn-xs js-confirm-submit">
                                                <!--js-confirm-submit js post 提交-->
                                                <i class="fa fa-trash-o"></i>移除
                                            </a>
                                        </td>
                                    </tr>
                                }
                            }

                        }
                    </tbody>

                </table>

            </div>

        </div>
        <!--endForm-->
    </div>
</div>
<div class="x_panel">
    <!--beginHead-->
    <div class="x_title">
        <h2>修改角色 <small>HANS</small></h2>
        <ul class="nav navbar-right panel_toolbox">
            <li>
                <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
            </li>
        </ul>
        <div class="clearfix"></div>
    </div>
    <!--endHead-->
    <div class="x_content">
        <!--beginForm-->
        @using (Html.BeginForm("UpdateRole", "Account", FormMethod.Post,
                                                new { @class = "form-horizontal form-label-left js-form-submit", @novalidate = "" }))
        {
        @Html.AntiForgeryToken()
        <div class="form-group">
            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">
                名称<span class="required">*</span>
            </label>
            <div class="col-md-6 col-sm-6 col-xs-12">
                @Html.TextBoxFor(i => i.Rolename, new { @class = "form-control col-md-7 col-xs-12", @placeholder = "中文" })
            </div>
            @Html.ValidationMessageFor(i => i.Rolename, null, new { @class = "text-danger" })

        </div>
        <div class="form-group">
            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">
                描述<span class="required">*</span>
            </label>
            <div class="col-md-6 col-sm-6 col-xs-12">
                @Html.TextAreaFor(i => i.Description, new { @class = "form-control col-md-7 col-xs-12" })
            </div>

        </div>
        <div class="form-group">
            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">
                权限<span class="required">*</span>
            </label>
            <div class="col-md-6 col-sm-6 col-xs-12">
                <div id="permissionTree"></div>
                @Html.Hidden("PermissionId")
            </div>

        </div>

        <div class="ln_solid"></div><!--一条横线-->
        <div class="form-group">
            <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                <button type="submit" class="btn btn-success">保存</button>
                <a href="@HttpContext.Current.Request.UrlReferrer" class="btn btn-default">取消</a>
            </div>
        </div>
        }
        <!--endForm-->
    </div>
</div>

